﻿@model IEnumerable<SDSystem.Models.ServiceMaintain>
@using Ext.Net.MVC;
@using Ext.Net;
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Header
{
    <script>
        function deactive() {
            if (App.DataGridPanel.getSelectionModel().getSelection()[0] == null) {
                alert('No contact selected');
                return;
            }
            var id = App.DataGridPanel.getSelectionModel().getSelection()[0].get('ServiceId');
            var name = App.DataGridPanel.getSelectionModel().getSelection()[0].get('ServiceName');
            var active = App.DataGridPanel.getSelectionModel().getSelection()[0].get('ServiceActive');
            if (active == true) {
                var bt = confirm('You are sure deactive record "' + name + '" ?');
                if (bt == true) {
                    App.direct.DeactiveService(id);
                }
            } else {
                alert('Service is deactive');
  
            }
        }

        function edit() {
            if (App.DataGridPanel.getSelectionModel().getSelection()[0] == null) {
                alert('No Service selected');
                return;
            }
            var id = App.DataGridPanel.getSelectionModel().getSelection()[0].get('ServiceId');
            showWindow('Edit Service', '/Service/Edit/' + id, true, 0.85, 0.85);

        }

        function copy() {
            if (App.DataGridPanel.getSelectionModel().getSelection()[0] == null) {
                alert('No Service selected');
                return;
            }
            var id = App.DataGridPanel.getSelectionModel().getSelection()[0].get('ServiceId');
            showWindow('Service Detail', '/Service/Detail/' + id, true, 0.85, 0.85);
  
        }
    </script>
    
    
}

@section ToolbarSection
{
@Html.X().ToolbarTextItem().Text("<h3 style=\"color:darkgreen\">Service List</h3>")
}

@* GridPanel *@
@(Html.X().GridPanel().ID("DataGridPanel")
      .Frame(true)
      .MultiSelect(true)
      .Store(Html.X().Store().ID("ServiceStore")
                 .Model(Html.X().Model().IDProperty("ServiceId")
                            .Fields(
                                new ModelField("ServiceId", ModelFieldType.Int),
                                new ModelField("ServiceName"),
                                new ModelField("ServiceShortDes"),
                                new ModelField("ServiceType"),
                                new ModelField("SureName"),
                                new ModelField("ServiceActive")
                            )
                 )
                 .RemoteSort(true)
                 .RemotePaging(true)
                 .RemoteFilter(true)
                 .PageSize(10)
                 .Proxy(
                     Html.X().AjaxProxy()
                         .Url(Url.Action("BindingStore"))
                         .Reader(Html.X().JsonReader().Root("data"))
                 )


      )
      .ColumnModel(
          Html.X().Column().Text("ID").DataIndex("ServiceId"),
          Html.X().TemplateColumn().Text("Service Name").TemplateString("<a href='javascript:void(0)' onclick='showWindow(\"Edit Service\",\"/Service/Edit/{ServiceId}\", true, 0.85, 0.85);'>{ServiceName}</a>").Flex(1),
          Html.X().Column().Text("Description").DataIndex("ServiceShortDes").Width(330),
          Html.X().Column().Text("Service Type").DataIndex("ServiceType").Flex(1),
          Html.X().Column().Text("Contact").DataIndex("SureName").Flex(1),
          Html.X().Column().Text("IsActive").DataIndex("ServiceActive").Flex(1),
          Html.X().CommandColumn().Text("Active").Width(50).Commands(
          Html.X().GridCommand().CommandName("Active").Icon(Icon.Accept).ToolTip(tt => tt.Text = "Active"))
                .Listeners(ls => ls.Command.Handler = "#{DirectMethods}.ActiveService(record.data.ServiceId);"),
          Html.X().CommandColumn().Text("De-Active").Width(60).Commands(
          Html.X().GridCommand().CommandName("DeActive").Icon(Icon.StopRed).ToolTip(tt => tt.Text = "DeActive"))
                .Listeners(ls => ls.Command.Handler = "deactive();"),
          Html.X().CommandColumn().Text("Delete").Width(50).Commands(
          Html.X().GridCommand().CommandName("Delete").Icon(Icon.Delete).ToolTip(tt => tt.Text = "Delete"))
                .Listeners(ls => ls.Command.Handler = "#{DirectMethods}.DeleteService(record.data.ServiceId);")
          //Html.X().Column().Editor(
          //    Html.X().MultiCombo()
          //            .Items(
          //              Html.X().ListItem().Text("Disability Living Allowance"),
          //              Html.X().ListItem().Text("Employment and Support Allowance"),
          //              Html.X().ListItem().Text("Incapacity Benifit"),
          //              Html.X().ListItem().Text("Income Support"),
          //              Html.X().ListItem().Text("Job Seekers Allowance")
          //))
                
        //.Listeners(ls => ls.Command.Handler = "showWindow('Delete','/Service/Delete/' + record.data.ServiceId,true,0.2,0.2);")

          )
          //.Plugins(
          //    Html.X().RowEditing()
          //                  .Listeners(l =>
          //                  {
          //                      l.CancelEdit.Handler = "#{DirectMethods}.AddOrgRole(record.data.ServiceId)";
          //                  })
          //)
          .TopBar(
              Html.X().Toolbar().Items(items =>
              {

                  items.Add(new LinkButton { Text = "All", Handler = "#{DirectMethods}.CharFilter('');", });

                  items.Add(new ToolbarSpacer());
                  items.Add(new ToolbarSeparator());
                  items.Add(new ToolbarSpacer());

                  items.Add(new LinkButton { Text = "0-9", Handler = "#{DirectMethods}.CharFilter('0');", });

                  items.Add(new ToolbarSpacer());
                  items.Add(new ToolbarSeparator());
                  items.Add(new ToolbarSpacer());

                  items.Add(new LinkButton { Text = "A", Handler = "#{DirectMethods}.CharFilter('A');", });
                  items.Add(new ToolbarSpacer());
                  items.Add(new LinkButton { Text = "B", Handler = "#{DirectMethods}.CharFilter('B');", });
                  items.Add(new ToolbarSpacer());
                  items.Add(new LinkButton { Text = "C", Handler = "#{DirectMethods}.CharFilter('C');", });
                  items.Add(new ToolbarSpacer());
                  items.Add(new LinkButton { Text = "D", Handler = "#{DirectMethods}.CharFilter('D');", });
                  items.Add(new ToolbarSpacer());
                  items.Add(new LinkButton { Text = "E", Handler = "#{DirectMethods}.CharFilter('E');", });
                  items.Add(new ToolbarSpacer());

                  items.Add(new ToolbarSpacer());
                  items.Add(new ToolbarSeparator());
                  items.Add(new ToolbarSpacer());

                  items.Add(new LinkButton { Text = "F", Handler = "#{DirectMethods}.CharFilter('F');", });
                  items.Add(new ToolbarSpacer());
                  items.Add(new LinkButton { Text = "G", Handler = "#{DirectMethods}.CharFilter('G');", });
                  items.Add(new ToolbarSpacer());
                  items.Add(new LinkButton { Text = "H", Handler = "#{DirectMethods}.CharFilter('H');", });
                  items.Add(new ToolbarSpacer());
                  items.Add(new LinkButton { Text = "I", Handler = "#{DirectMethods}.CharFilter('I');", });
                  items.Add(new ToolbarSpacer());
                  items.Add(new LinkButton { Text = "J", Handler = "#{DirectMethods}.CharFilter('J');", });
                  items.Add(new ToolbarSpacer());

                  items.Add(new ToolbarSpacer());
                  items.Add(new ToolbarSeparator());
                  items.Add(new ToolbarSpacer());

                  items.Add(new LinkButton { Text = "K", Handler = "#{DirectMethods}.CharFilter('K');", });
                  items.Add(new ToolbarSpacer());
                  items.Add(new LinkButton { Text = "L", Handler = "#{DirectMethods}.CharFilter('L');", });
                  items.Add(new ToolbarSpacer());
                  items.Add(new LinkButton { Text = "M", Handler = "#{DirectMethods}.CharFilter('M');", });
                  items.Add(new ToolbarSpacer());
                  items.Add(new LinkButton { Text = "N", Handler = "#{DirectMethods}.CharFilter('N');", });
                  items.Add(new ToolbarSpacer());

                  items.Add(new ToolbarSpacer());
                  items.Add(new ToolbarSeparator());
                  items.Add(new ToolbarSpacer());

                  items.Add(new LinkButton { Text = "O", Handler = "#{DirectMethods}.CharFilter('O');", });
                  items.Add(new ToolbarSpacer());
                  items.Add(new LinkButton { Text = "P", Handler = "#{DirectMethods}.CharFilter('P');", });
                  items.Add(new ToolbarSpacer());
                  items.Add(new LinkButton { Text = "Q", Handler = "#{DirectMethods}.CharFilter('Q');", });
                  items.Add(new ToolbarSpacer());
                  items.Add(new LinkButton { Text = "R", Handler = "#{DirectMethods}.CharFilter('R');", });
                  items.Add(new ToolbarSpacer());

                  items.Add(new ToolbarSpacer());
                  items.Add(new ToolbarSeparator());
                  items.Add(new ToolbarSpacer());

                  items.Add(new LinkButton { Text = "S", Handler = "#{DirectMethods}.CharFilter('S');", });
                  items.Add(new ToolbarSpacer());
                  items.Add(new LinkButton { Text = "T", Handler = "#{DirectMethods}.CharFilter('T');", });
                  items.Add(new ToolbarSpacer());
                  items.Add(new LinkButton { Text = "U", Handler = "#{DirectMethods}.CharFilter('U');", });
                  items.Add(new ToolbarSpacer());
                  items.Add(new LinkButton { Text = "V", Handler = "#{DirectMethods}.CharFilter('V');", });
                  items.Add(new ToolbarSpacer());

                  items.Add(new ToolbarSpacer());
                  items.Add(new ToolbarSeparator());
                  items.Add(new ToolbarSpacer());

                  items.Add(new LinkButton { Text = "W", Handler = "#{DirectMethods}.CharFilter('W');", });
                  items.Add(new ToolbarSpacer());
                  items.Add(new LinkButton { Text = "X", Handler = "#{DirectMethods}.CharFilter('X');", });
                  items.Add(new ToolbarSpacer());
                  items.Add(new LinkButton { Text = "Y", Handler = "#{DirectMethods}.CharFilter('Y');", });
                  items.Add(new ToolbarSpacer());
                  items.Add(new LinkButton { Text = "Z", Handler = "#{DirectMethods}.CharFilter('Z');", });
                  items.Add(new ToolbarSpacer());

                  items.Add(new ToolbarFill());


                  items.Add(new Button
                  {
                      Text = "<b>Create</b>",
                      Margins = "0 20 0 0",
                      Icon = Icon.Add,
                      OnClientClick = "showWindow('Create Service','/Service/Create',true,0.85,0.85);"

                  });


                  items.Add(new Checkbox
                  {
                      FieldLabel = "<b>Include In-Active</b>",
                      Margins = "0 20 0 0",
                      LabelWidth = 120,
                      LabelAlign = LabelAlign.Right,
                      DirectCheckAction = "IncludeInActive"
                  });

              })
          )
          .BottomBar(Html.X().PagingToolbar())

          )
<div style="margin-top: 10px">
    @Html.X().ButtonGroup().Items(
        Html.X().Button().Text("Edit").Icon(Icon.Pencil).Listeners(
            li => li.Click.Handler = "edit();"
            ),
        Html.X().Button().Text("Copy").Icon(Icon.DatabaseCopy).Listeners(
            li=> li.Click.Handler="copy();"
           )
         )
</div>
